package com.kingint.web.portal.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kingint.mbg.bas.entity.BasDepartment;
import com.kingint.mbg.bas.mapper.BasDepartmentMapper;
import com.kingint.mbg.dto.BackQueryParam;
import com.kingint.mbg.dto.MemberReturn;
import com.kingint.mbg.sys.entity.UmsMember;
import com.kingint.mbg.sys.mapper.UmsMemberMapper;
import com.kingint.web.portal.base.service.DepartmentService;
import com.kingint.web.sys.service.UmsAdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class DepartmentServiceImpl implements DepartmentService {

    @Resource
    private UmsAdminService adminService;
    @Resource
    private BasDepartmentMapper departmentMapper;
    @Resource
    private UmsMemberMapper memberMapper;

    @Override
    public List<BasDepartment> getAllDepartmentList() {
        UmsMember currentMember = adminService.getCurrentMember();
        Integer hotelId = currentMember.getHotelId();
        if (StringUtils.isEmpty(hotelId)) {
            log.debug("当前登录账号没有关联酒店");
            return null;
        }
        QueryWrapper<BasDepartment> wrapper = new QueryWrapper<>();
        wrapper.eq("hotel_id", hotelId)
                .eq("status", 0);
        List<BasDepartment> basDepartments = departmentMapper.selectList(wrapper);
        return basDepartments;
    }

    @Override
    public List<MemberReturn> getDepartmentOnePerson(Integer departmentId, Integer workStatus) {
        List<MemberReturn> departmentUser = memberMapper.getDepartmentUser(departmentId, workStatus);
        return departmentUser;
    }

    @Override
    public List<BasDepartment> getDepartmentListByHotelId(Integer hotelId) {
        QueryWrapper<BasDepartment> wrapper = new QueryWrapper<>();
        wrapper.eq("hotel_id",hotelId)
                .eq("status",0);
        List<BasDepartment> list = departmentMapper.selectList(wrapper);
        return list;
    }

    @Override
    public List<BasDepartment> getPhoneList(BackQueryParam queryParam) {
        UmsMember currentMember = adminService.getCurrentMember();
        queryParam.setHotelId(currentMember.getHotelId());
        List<BasDepartment> departmentList = departmentMapper.getDepartmentList(queryParam);
        return departmentList;
    }
}
